import {getLocalStorage, setLocalStorage} from "@/utils/localstore";

const state = {
    token: getLocalStorage('token'),
    identity: [],
    userIdentity: undefined
};

const mutations = {
    setIdentity: (state, indentity) => {
        state.identity = indentity;
    },
    clearIdentity: (state, indentity) => {
        state.identity = indentity;
    },
    setToken: (state, token) => {
        state.token = token
    }
};

const actions = {
    actionToken: ({commit, state}, info) => {
        state.userIdentity = info.trueName;
        setLocalStorage('token', info.token);
        setLocalStorage('userName', info.trueName);
        commit('setToken', info.token);
    },
    actionIdentity: ({commit}, identity) => {
        commit('setIdentity', [identity])
    }
};

export default {
    namespaced: true,
    state,
    mutations,
    actions
}

